#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 即将拥有人鱼线的yjw
   @Time: 2025/5/30 15:35
   @File: getPackageInfo.py
   @desc:
"""
import json

import pandas
from dateutil import parser
from BladeFerm.utils.basic_opration import run_command


def search_zip_from_jfrog(path):
    # path = ' "aml5.0-generic-test-local/os/AML5.0V202501/AML5.0V202501.05.000/"'
    cmd_download = f".\\tools\jfrog.exe  rt search {path} --recursive --include-dirs"
    res = run_command(cmd_download)
    combined_bytes = b''.join(res)
    json_str = combined_bytes.decode('utf-8')
    packets = json.loads(json_str)
    packets_list = []
    for packet in packets:
        list1 = packet['path'].split('/')
        dt = parser.isoparse(packet['modified'])
        modiy_time = dt.strftime("%Y-%m-%d %H:%M:%S")
        packets_list.append({'程序包名': list1[-1], '程序日期': modiy_time, '程序包大小': str(packet['size']), '发布版本号': list1[-2]})

    print(packets_list)
    df = pandas.DataFrame(packets_list)
    return df

if __name__ == '__main__':
    path = 'aml5.0-generic-test-local/os/AML5.0V202501/AML5.0V202501.05.000/'
    search_zip_from_jfrog(path)

